import selfApi from 'api/selfApi'
import * as types from '../mutation-types'
import { setServerTime } from '@/common/auth'

const getDefaultState = () => {
  return {
    depCode:''
  }
}

const state = getDefaultState()

const mutations = {
  [types.RESET_STATE]: (state) => {
    Object.assign(state, getDefaultState())
  },
  [types.DEP_CODE](state, data) {
	  state.depCode = data
	},
  
}

const actions = {
  // 获取服务器时间
  _getServerTime({ state, commit }) {
    return new Promise((resolve, reject) => {
      selfApi.login.getServerTime().then((response) => {
        const date = new Date()
        const diffTime = date.getTime() - response
        setServerTime(diffTime)
        resolve()
      }).catch(err => {
        reject(err)
      })
    })
  },

	// 清楚common里的数据
  removeData({ state, commit }) {
    
  }
}

export default {
  state,
  actions,
  mutations
}
